import Vue from 'vue';
import VueI18n from 'vue-i18n'
import ElementUI from 'element-ui'
import enLocale from 'element-ui/lib/locale/lang/en'
import zhLocale from 'element-ui/lib/locale/lang/zh-CN'
import locale from 'element-ui/lib/locale'

if (Vue.config.lang == 'en') {
    Vue.use(ElementUI, { locale: enlocale });
} else {
    Vue.use(ElementUI);
}
Vue.use(VueI18n);

let zh = require('./zh.json');
let en = require('./en.json');
let countryzh = require('./country_zh.json');
let countryen = require('./country_en.json');

const locales = {
  zh: {
  	message:{
  		...zh,
  		...countryzh,
			...zhLocale
  	}
  },
  en: {
  	message:{
  		...en,
  		...countryen, //
			...enLocale
  	}
  },
}

const i18n = new VueI18n({
    locale: JSON.parse(localStorage.getItem('locale')) || 'zh',  // 语言标识
    messages:locales
})

locale.i18n((key, value) => i18n.t(key, value)) //为了实现element插件的多语言切换

export default i18n;